// CrashHandler.h: interface for the CCrashHandler class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_CRASHHANDLER_H__724E99B4_C261_44E2_9F39_439CE8E62347__INCLUDED_)
#define AFX_CRASHHANDLER_H__724E99B4_C261_44E2_9F39_439CE8E62347__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include <windows.h>
#include <imagehlp.h>
#include <vector>
using namespace std;

#pragma comment(lib, "imagehlp.lib")

#define SAFEDELETE(p)\
delete p;\
p = NULL;

class CCrashHandler
{
	FILE*			m_pFile;
	TCHAR			m_szPath[MAX_PATH];
	
protected:
	static CCrashHandler*		m_pThis;
public:
    void Exit(char* szErrMsg);
	void ReportErrMsg(char* szErrMsg);
	void ReportLastCompiled();
	void ReportTime(SYSTEMTIME &sSysTime);
	void ReportCrash();
	void Report(char* szErrMsg);
	static LONG ExceptionCallBack(EXCEPTION_POINTERS *pExPtrs);
	void Release();
	BOOL Init();
	CCrashHandler();
	virtual ~CCrashHandler();

	static inline CCrashHandler* GetThis()		{ return m_pThis; }
	static inline void Create()					{ new CCrashHandler(); }
	static inline void Destroy()				{ SAFEDELETE(m_pThis); }

};

inline CCrashHandler* _CrashHandler()
{
	return CCrashHandler::GetThis();
}

#endif // !defined(AFX_CRASHHANDLER_H__724E99B4_C261_44E2_9F39_439CE8E62347__INCLUDED_)
